package com.heima.media.task;

import com.heima.media.entity.WmNews;
import com.heima.media.service.IAuditService;
import com.heima.media.service.IWmNewsService;
import org.redisson.api.RBlockingDeque;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class ArticleTask {
    @Autowired
    private RedissonClient redissonClient;

    @Autowired
    private IWmNewsService wmNewsService;
    @Autowired
    private IAuditService iAuditService;

    @Async
    public void receiveMesasge()throws Exception{
        RBlockingDeque<Object> blockingDeque = redissonClient.getBlockingDeque("article-bqueue");
        while (true){
            Object poll = blockingDeque.poll(30, TimeUnit.SECONDS);
            if(poll!=null){
                Integer integer = Integer.valueOf(poll.toString());
                WmNews wmNews = wmNewsService.getById(integer);
                Long article = iAuditService.saveArticle(wmNews);
            }
        }
    }
}
